;;; init-base.el  -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2023 gotpl
;;
;; Author: gotpl <631707329@qq.com>
;; Maintainer: gotpl <631707329@qq.com>
;; Created: 七月 27, 2023
;; Modified: 七月 27, 2023
;; Version: 0.0.1
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
;; Homepage: https://github.com/gotpl/init-base
;; Package-Requires: ((emacs "24.3"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;;
;;
;;; Code:

;; 固定行号宽度
(setq display-line-numbers-width-start t)

;; 像素滚动
(add-hook 'find-file-hook (lambda ()
                    (when (not pixel-scroll-precision-mode)
                      (pixel-scroll-precision-mode 1)
                      (setq pixel-scroll-precision-interpolate-page t)
                      (message "pixel-scroll-precision-mode is turning on."))))
;; (pixel-scroll-precision-mode 1)
;; (setq pixel-scroll-precision-interpolate-page t)
;; (setq pixel-scroll-precision-interpolation-total-time 0.3)

;; No backup files
(setq make-backup-files nil
      ;; auto-save-default nil
      )
(setq-default auto-save-timeout 15) ; 15秒无动作,自动保存
(setq-default auto-save-interval 100) ; 100个字符间隔, 自动保存

;; No lock files
(setq create-lockfiles nil)

;; Always load the newest file
(setq load-prefer-newer t)
;; 打开帮助窗口自动焦点移动到新窗口
(setq help-window-select t)

;; Smooth scroll & friends
;; (setq scroll-step 2
;;       scroll-margin 2
;;       hscroll-step 2
;;       hscroll-margin 2
;;       scroll-conservatively 101
;;       scroll-preserve-screen-position 'always)
(setq-default fill-column 80)

;; No tabs
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)

;; Back to the previous position
(defun load-saveplace! ()
  (require 'saveplace)
  (save-place-mode))
(use-package saveplace
  :ensure nil
  :hook (emacs-startup . load-saveplace!))

;; Enable `repeat-mode' to reduce key sequence length
;; 重复命令 前一次的命令，第一次输入完整的 C-x z,超时时间内只需要再按z即可重复第二次,即C-x z开始重复，后面超时时间内只需要z即可
;; If we have been idle for `repeat-exit-timeout' seconds, exit the repeated
;; state.

(defun load-repeat! ()
  (require ' repeat)
  (repeat-mode))
(use-package repeat
  :ensure nil
  :hook (emacs-startup . load-repeat!)
  :config
  (setq repeat-mode t)
  (setq repeat-exit-timeout 3)
  (setq repeat-exit-key (kbd "RET")))

;; Recently opened files
(use-package recentf
  :ensure nil
  :hook (emacs-startup . recentf-mode)
  :config
  (setq recentf-max-saved-items 300)
  (setq recentf-auto-cleanup 'never)
  (setq recentf-exclude '(;; Folders on MacOS start
                     "^/private/tmp/"
                     "^/var/folders/"
                     "\.emacs.d/.cache/treemacs-persist"
                     ;; Folders on MacOS end
                     "^/tmp/"
                    ;;  "/ssh\\(x\\)?:"
                     "/su\\(do\\)?:"
                     "^/usr/include/"
                     "/TAGS\\'"
                     "COMMIT_EDITMSG\\'")))

(defun load-orderless! ()
  (require 'orderless))
(use-package orderless
  :hook (emacs-startup . load-orderless!)
  :config
  (setq completion-styles '(orderless)))

;; 外部修改自动刷新
;; add-hook函数lambda使用时加'启动时间变长， lambda本身就有'效果
;; (add-hook 'emacs-startup (lambda () (global-auto-revert-mode 1)))
(add-hook 'emacs-startup-hook (lambda () (global-auto-revert-mode 1)))


(use-package buffer-move
  :bind (
         ([C-S-down] . buf-move-down)
         ([C-S-up] . buf-move-up)
         ([C-S-left] . buf-move-left)
         ([C-S-right] . buf-move-right)
         ))
;; y-or-no替换yes-or-no
(fset 'yes-or-no-p 'y-or-n-p)

(winner-mode 1)
;; 记住命令的历史记录
(defun load-savehist! ()
  (require 'savehist)
  (savehist-mode))
(use-package savehist
  :ensure nil
  :hook (emacs-startup . load-savehist!)
  :init
  (setq enable-recursive-minibuffers t ; Allow commands in minibuffers
          history-length 1000
          savehist-additional-variables '(mark-ring
                          global-mark-ring
                          search-ring
                          regexp-search-ring
                          extended-command-history)
          savehist-autosave-interval 300)
  )

(electric-pair-mode 1) ;; 括号、引号成双对


(setq system-time-locale "C") ;; 时间日期统一英文格式

(use-package restart-emacs
  :ensure nil
  :commands restart-emacs) ;; 29 buildin

(provide 'init-base)
;;; init-base.el ends here
